clear
rng default

workers=500;
n_types=4;

fp0='.../r4/[5]'; %use the correct path


miss_M=cell(n_types,1);
miss_W=cell(n_types,1);

%MEN
for j=1:n_types

fp=['.../r4/[5]/M/M_', int2str(j)];  %use the correct path


IdSetM_temp=cell(workers,1);
miss_temp=[];
for ii = 1:workers
    filepath = fullfile( fp, ['IdSetM.' num2str(ii) '.mat'] );
    if exist( filepath, 'file' )
       A = getfield( load( filepath ), 'IdSetM' ); 
       IdSetM_temp{ii}=A;
    else
        miss_temp=[miss_temp ii];
    end
end
miss_M{j}=miss_temp;
IdSetM_final= vertcat(IdSetM_temp{:}); 

outpath = fullfile( fp0, ['IdSetM_final_' num2str(j) '.mat'] );
save( outpath, 'IdSetM_final' );
end



%WOMEN
for j=1:n_types

fp=['.../r4/[5]/W/W_', int2str(j)]; 


IdSetM_temp=cell(workers,1);
miss_temp=[];
for ii = 1:workers
    filepath = fullfile( fp, ['IdSetM.' num2str(ii) '.mat'] );
    if exist( filepath, 'file' )
       A = getfield( load( filepath ), 'IdSetM' ); 
       IdSetM_temp{ii}=A;
    else
        miss_temp=[miss_temp ii];
    end
end
miss_W{j}=miss_temp;
IdSetW_final= vertcat(IdSetM_temp{:}); 

outpath = fullfile( fp0, ['IdSetW_final_' num2str(j) '.mat'] );
save( outpath, 'IdSetW_final' );
end

 

